﻿<?php
//print_r($_POST);die;//Array ( [usname] => wanmingming [pass] => 123456 [remember] => 1 [sub] => 登录 )
include_once("../function.php");
//判断是否通过表单提交
if(!isset($_POST["sub"]))
{
	msg("请通过表单提交","./deng.php");
	exit;
}
extract($_POST);//$usname $pass $remember

//数据处理
$usname=trim($usname);
$pass=trim($pass);

//判断账户和密码是否为空
if(!empty($usnmae)||empty($pass))
{
	msg("账户和密码不能为空","./login.php");exit;	
}
//判断是否登录成功
$pwd=md5($pass);
$sql="select * from ts_user where username='$usname'";
//echo $sql;die;
$res=mysqli_query($link,$sql);
//var_dump($res);die;
if(is_object($res))
{
	if(mysqli_num_rows($res)>0)
	{//echo 5;die;
	 $one=mysqli_fetch_assoc($res);
	 if($one["ifshow"]==0)
         {
  		msg("账户已被封","./login.php");exit;	
         }
	//print_r($one);die;
	 if($one['username']=="$usname"&&$one['password']==$pwd)
	   {
		  if(isset($remember)&&$remember==1)
		   {
				setCookie("usname",$usname,time()+24*3600,"/");
				setCookie("pwd",$pass,time()+24*3600,"/");
				setCookie("rem","on",time()+24*3600,"/");
		   }
		  else
		   {
				setCookie("usname",$usname,time()-1,"/");
				setCookie("pwd",$pass,time()-1,"/");
				setCookie("rem","on",time()-1,"/");	
		   }
		setCookie("username",$usname,time()+24*3600*7,"/");
		setCookie("userid",$one["uid"],time()+24*3600*7,"/");
		msg("登录成功","./index.php");exit;
		} 
	}
	else
	{	
		msg("登录失败","./login.php");exit;	
	}
}
else
{
	msg("您没有注册,请先注册!","regist.php");exit;
}
/*
$pwd=md5($pass);
$sql="select * from ts_user where username='$usname',password='$pwd'";
$res=mysqli_query($link,$sql);
if(is_object($res))
{
	$one=mysqli_fetch_assoc($res);
	{
	  if($one['username']=='$usname'&&$one['password']=='$pwd')
	   {
		if(isset($remember)&&$remember==1)
		 {
			setCookie("usname",$usname,time()+24*3600,"/");
			setCookie("pwd",$pass,time()+24*3600,"/");
			setCookie("rem","on",time()+24*3600,"/");
		 }
		 else
		 {
			setCookie("usname",$usname,time()-1,"/");
			setCookie("pwd",$pass,time()-1,"/");
			setCookie("rem","on",time()-1,"/");	
		 }
		 setCookie("username",$usname,time()+24*3600*7,"/");
		 setCookie("userid",$one[uid],time()+24*3600*7,"/");
		 msg("登录成功","./index.php");exit;
	   }
	}
	else
	{
		msg("登录失败","./login.php");exit;	
	}
}
else
{
	msg("您没有注册,请先注册!","regist.php");
	exit;
}*/

?>